<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>商品管理</li>
    <li>添加</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>商品类型信息</span></div>
  <form action="/purchase/cproduct/doadd" method="post">
    <span style="font-weight: bold; color: red;" th:text="${msg}"></span>
  <ul class="forminfo">
    <li>
      <label>品牌名称</label>
      <select class="dfselect" onchange="getbrands(this.value)" name="brandId" id="brandId">
        <!--<option value="0">请选择</option>
        <option th:each="cb :${cbrands}" th:value="${cb.brandId}" th:text="${cb.brandName}">联想</option>-->
      </select>
      <i>必选</i>
    </li>
    <li>
      <label>商品类型</label>
      <select class="dfselect" name="typeId" id="typeId">
      	  <option value="0">请选择</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>商品型号</label>
      <input name="productModel" type="text" class="dfinput" />
      <i>必填，不能超过50个字符</i>
    </li>
    <li>
      <label>产商</label>
      <select class="dfselect" name="firmId" id="firmId">
        <option value="0">请选择</option>
      </select>
      <i>必选</i>
    </li>
    <li>
      <label>单位</label>
      <input name="productUnit" type="text" class="dfinput" />
      <i>必填，不能超过10个字符</i>
    </li>
    <li>
      <label>单价</label>
      <input name="productPrice" type="text" class="dfinput" id="productPrice"/>
      <i>必填，不能超过10个字符</i>
    </li>
    <li>
      <label>状态</label>
      <select class="dfselect" name="productStatus">
          <option value="1">可用</option>
          <option value="2">不可用</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>创建人</label>
      <input type="hidden" name="createId" th:value="${session.users.UId}">
      <input name="" type="text" th:value="${session.users.uname}" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>创建时间</label>
      <input name="createTime" type="text" value="2017-11-18 15:36:10" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>&nbsp;</label>
      <input name="" type="submit" class="btn" value="确定"/>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="" type="button" class="btn" value="返回" onclick="window.location.href='/purchase/cproduct/cplist'"/>
    </li>
  </ul>
  </form>
</div>
<script>
  var date = new Date();
  var seperator = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentDate = year + seperator + month + seperator + strDate; //当前日期
  $("input[name=createTime]").val(currentDate);

  function getbrands(num) {
    $.get("/erp/purchase/cproduct/ajaxtypes",{"brandid":num},function (data) {
      //alert(typeof(data));
      $("select[name=typeId]").html("");
      var options="<option value='0'>请选择</option>";
      $.each(data,function (i,e) {
        options+="<option value='"+e.typeId+"'>"+e.typeName+"</option>";
      });
      $("select[name=typeId]").append(options);
    },"json");
  }
  /*查询品牌*/
  function pai(){
    $.ajax({
      url: "/purchase/cproduct/selectpai",
      type: "post",
      datatype: "json",
      success: function (data) {
        var str="<option value=\"\">请选择</option>"
        for (var i=0;i<data.length;i++){
          str+="<option value=\""+data[i].brandId+"\">"+data[i].brandName+"</option>"
        }
        $("#brandId").html(str)
      }
    });
  }
  /*【品牌内容发生改变是触发的事件----查类型*/
  $("#brandId").change(function (){
    $.ajax({
      url: "/purchase/cproduct/selecttype",
      data:{brandId:$("#brandId").val()},
      type: "post",
      datatype: "json",
      success: function (data) {
        var str="<option value=''>请选择</option>"
        for (var i=0;i<data.length;i++){
          str+="<option value=\""+data[i].typeId+"\">"+data[i].typeName+"</option>"
        }
        $("#typeId").html(str)
      }
    });
  })
  /*查询厂商*/
  function chang(){
    $.ajax({
      url: "/purchase/cproduct/chang",
      type: "post",
      datatype: "json",
      success: function (data) {
        var str="<option value=''>请选择</option>"
        for (var i=0;i<data.length;i++){
          str+="<option value=\""+data[i].firmId+"\">"+data[i].firmName+"</option>"
        }
        $("#firmId").html(str)
      }
    });
  }
  $(function (){
    pai();
    chang();
  })
</script>
</body>
</html>
